package com.gongfutrip.trans.client.common;

import com.gongfutrip.trans.client.exception.ClientException;

import java.util.ArrayList;
import java.util.List;

public class ProducerConfig {
  private int maxMessageSize = 1024 * 1024 * 4; // 4M
  private int sendMsgTimeout = 3000;// 测试
  private int retryTimesWhenSendFailed = 2;// 同步重试次数
  private int retryTimesWhenSendAsyncFailed = 2;// 异步重试次数



  public volatile static String namesrvAddr =
      "127.0.0.1:8888;192.168.3.21:8888;192.168.3.21:8889;192.168.3.11:8888";// 指定服务器地址
  // 192.168.0.1:9876;192.168.0.2:9876

  public int getSendMsgTimeout() {
    return sendMsgTimeout;
  }

  public void setSendMsgTimeout(int sendMsgTimeout) {
    this.sendMsgTimeout = sendMsgTimeout;
  }

  public int getMaxMessageSize() {
    return maxMessageSize;
  }

  public void setMaxMessageSize(int maxMessageSize) {
    this.maxMessageSize = maxMessageSize;
  }


  public int getRetryTimesWhenSendAsyncFailed() {
    return retryTimesWhenSendAsyncFailed;
  }

  public void setRetryTimesWhenSendAsyncFailed(int retryTimesWhenSendAsyncFailed) {
    this.retryTimesWhenSendAsyncFailed = retryTimesWhenSendAsyncFailed;
  }

  public int getRetryTimesWhenSendFailed() {
    return retryTimesWhenSendFailed;
  }

  public void setRetryTimesWhenSendFailed(int retryTimesWhenSendFailed) {
    this.retryTimesWhenSendFailed = retryTimesWhenSendFailed;
  }

  public static List<String> getNamesrvAddrList() throws ClientException {
    if (null == namesrvAddr || "".equals(namesrvAddr)) {
      throw new ClientException("no namesrvAddr");
    }
    String[] address = namesrvAddr.split(";");
    List<String> list = new ArrayList<String>();
    if (null != address) {
      for (int i = 0; i < address.length; i++) {
        list.add(address[i]);
      }
    }
    return list;
  }

}
